package com.kangkang.leetcode10;

public class Test9 {
    public static void main(String[] args) {
        int[] a= {0,2,3};
        System.out.println(Solution9.canJump1(a));
    }
}
class Solution9 {
    public static boolean canJump(int[] nums) {
        if(nums.length==1)return true;
        int[] index = new int[nums.length];
        index[0] = 1;
        for (int i = 0; i < nums.length-1; i++) {
            if(nums[i] != 0)
            for (int j = 1; j <= nums[i]; j++) {
                if(j+i < nums.length){index[i+j] = 1;}
            }
        }
        for (int i : index) {
            if(i == 0)return false;
        }
        return true;
    }
    public static boolean canJump1(int[] nums) {
        if(nums[0] == 0) return false;

        int index = 0;
        for (int i = 0; i < nums.length-1; i++) {

            if(nums[i] + i > index){
                index = nums[i] + i;
            }
        }
        System.out.println(index);
        return index + 1 >= nums.length;
        }
}